package com.dianjing.dianjing.util;

import cn.hutool.http.HttpStatus;
import lombok.Data;

/**
 * @Author liangbaigao
 * @Date 2022/10/26 8:17
 */
@Data
public class DataUtils {

    {
        this.code = HttpStatus.HTTP_CREATED;
        this.msg = "create";
    }

    // 消息
    private String msg;

    // 状态
    private Integer code;

    // 数据
    private Object data;

    public DataUtils(){}

    public DataUtils(Object data){
        this.data = data;
    }

    public DataUtils(String msg, Object data){
        this.data = data;
        this.msg = msg;
    }

    public static DataUtils ok(){
        DataUtils dataUtils = new DataUtils();
        dataUtils.code = HttpStatus.HTTP_OK;
        dataUtils.msg = "ok";
        dataUtils.data = "ok";
        return dataUtils;
    }

    public static DataUtils ok(Object data){
        DataUtils dataUtils = new DataUtils();
        dataUtils.code = HttpStatus.HTTP_OK;
        dataUtils.data = data;
        dataUtils.msg = "ok";
        return dataUtils;
    }

    public static DataUtils ok(String msg,Object data){
        DataUtils dataUtils = new DataUtils();
        dataUtils.code = HttpStatus.HTTP_OK;
        dataUtils.msg = msg;
        dataUtils.data = data;
        return dataUtils;
    }

    public static DataUtils error(String msg,Object data){
        DataUtils dataUtils = new DataUtils();
        dataUtils.code = HttpStatus.HTTP_INTERNAL_ERROR;
        dataUtils.msg = msg;
        dataUtils.data = data;
        return dataUtils;
    }

    public static DataUtils error(Object data){
        DataUtils dataUtils = new DataUtils();
        dataUtils.code = HttpStatus.HTTP_INTERNAL_ERROR;
        dataUtils.msg = "未知错误，请联系管理员";
        dataUtils.data = data;
        return dataUtils;
    }

}
